package edu.pitt.cs.cs2410pj2.util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class ParameterReader {
	public static Parameters getDebugPara() {
		Parameters para = new Parameters();
		para.p = 1;
		para.n1 = 8;
		para.n2 = 10;
		para.a1 = 1;
		para.a2 = 1;
		para.b = 2;
		para.C = 1;
		para.d = 2;
		para.d1 = 4;
		return para;
	}
	
	public static Parameters loadParameters(String filePath) throws IOException {
		Parameters para = new Parameters();
		BufferedReader reader = new BufferedReader(new FileReader(filePath));
		String line = reader.readLine();
		while (line != null) {
			String[] tokens = line.split("=");
			if (tokens.length > 1) {
				setValue(para, tokens[0], Integer.parseInt(tokens[1]));
			}
			line = reader.readLine();
		}
		return para;
	}

	public static void setValue(Parameters para, String token, int value) {
		if (token.equals("p")) {
			para.p = value;
		} else if (token.equals("n1")) {
			para.n1 = value;
		} else if (token.equals("n2")) {
			para.n2 = value;
		} else if (token.equals("b")) {
			para.b = value;
		} else if (token.equals("a1")) {
			para.a1 = value;
		} else if (token.equals("a2")) {
			para.a2 = value;
		} else if (token.equals("C")) {
			para.C = value;
		} else if (token.equals("d")) {
			para.d = value;
		} else if (token.equals("d1")) {
			para.d1 = value;
		}
	}
	
	public static void main(String[] args) throws IOException {
		Parameters para = loadParameters("config.txt");
		System.out.println(para);
	}
}
